<?php

/**
 * Class TermUpdateAction
 */
class TermUpdateAction extends CAction
{
	public $view = 'termUpdate';

	public function run($id)
	{
		$model = $this->loadModel($id);
		$model->taxonomy = Taxonomy::model()->findFromCache($model->taxonomy_id);

		if (isset($_POST['Term'])) {
			$model->attributes = $_POST['Term'];
			if ($model->save()) {
				Yii::app()->getUser()->setFlash('success', '术语更新成功');
				$url = array('view', 'id' => $model->taxonomy_id);
				$this->getController()->redirect($url);
			}
		}

		$this->getController()->render($this->view, array('model' => $model));
	}

	public function loadModel($id)
	{
		if (!$model = Term::model()->findByPk($id)) {
			throw new CHttpException(404, '页面没有找到');
		}
		return $model;
	}
}